layui.use(['form', 'layer', 'laydate'], function () {
    const form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laydate = layui.laydate,
        $ = layui.jquery;

    //请选择发证日期
    laydate.render({
        elem: '.doctorWorkDate',
        format: 'yyyy-MM-dd',
        trigger: 'click',
        max: 0,
        mark: {"0-1-1": "元旦"},
        done: function (value, date) {
            if (date.month === 1 && date.date === 1) { //点击每年12月15日，弹出提示语
                layer.msg('今天是元旦，新年快乐！');
            }
        }
    });

    $.ajax({
        url: $.cookie("tempUrl") + "hSysDoctor/selectByPrimaryKey?id=" + $.cookie("doctorId"),
        type: "GET",
        success: function (result) {
            if (result.code === 200) {
                form.val("formTest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                    "doctorWorkCode": result.data.doctorWorkCode,
                    "grlabel": result.data.grlabel,
                    "employmentTime": result.data.employmentTime,
                    // "doctorWorkDate": result.data.doctorWorkDate == null ? "" : result.data.doctorWorkDate.substring(0, result.data.doctorWorkDate.indexOf(' ')),
                    "briefIntroduction": result.data.briefIntroduction,
                    "beGoodAt": result.data.beGoodAt,
                    "notice": result.data.notice
                });
                let arr = result.data.grlabel;
                console.log(arr.split(','));
                // let strArray = arr.split(',');
                // for (let index in strArray) {
                //     alert(strArray[index]);
                // }
            } else {
                layer.msg("加载异常", {icon: 7, anim: 6});
            }
        }
    });

    form.on("submit(submit)", function (data) {
        layer.confirm('修改信息将会被重新审核，是否确认?', {title: '系统提示', area: ['320px', '200px']}, function (index0) {
            //do something
            //弹出loading
            const index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
            $.ajax({
                url: $.cookie("tempUrl") + "hSysDoctor/updateByPrimaryKeySelectiveForDetail",
                type: "PUT",
                datatype: "application/json",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify({
                    id: $.cookie("doctorId"),
                    doctorWorkCode: data.field.doctorWorkCode,
                    employmentTime: data.field.employmentTime,
                    // doctorWorkDate: data.field.doctorWorkDate === "" ? null : data.field.doctorWorkDate + " 00:00:00",
                    grlabel: data.field.grlabel,
                    briefIntroduction: data.field.briefIntroduction,
                    beGoodAt: data.field.beGoodAt,
                    notice: data.field.notice
                }),
                success: function (result) {
                    if (result.code === 200) {
                        layer.msg("更新成功");
                        setTimeout(function () {
                            top.layer.close(index);
                            // top.layer.msg("新增成功2");
                            layer.closeAll("iframe");
                            //刷新本页面
                            location.reload();
                        }, 500);
                    } else {
                        layer.msg('更新异常', {icon: 7, anim: 6});
                    }
                }
            });

            layer.close(index);
        });
        return false;
    });
});